package cn.tedu.utils.jdbc;/**
 * @Author 金帮嘉诚 @Date 2021-07-15 星期四 10:07
 * 知识点
 */
/*本类用于测试*/

/**知识点*/

import com.sun.org.apache.xalan.internal.xsltc.dom.CurrentNodeListFilter;

import java.sql.*;
import java.util.ConcurrentModificationException;

/**链接
 * mysql数据库 cgb2105数据库的spb_student表*/
public class JdbcUtils {

    /**链接*/
    public static Connection getCon() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql:///cgb2105?characterEncoding=utf8";
        Connection connection = DriverManager.getConnection(url, "root", "root");
        return connection;
    }

    /**关闭*/
    public static void closeRPC(ResultSet resultSet, PreparedStatement preparedStatement, Connection connection) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
}
